# 作者: 赵若云
# 2025年02月20日16时50分36秒
# 3478783573@qq.com

def use_except():
    """
    练习简单的异常捕获
    :return:
    """
    while True:
        try:
            num = int(input('请输入数字'))
            print(num)
            break
        except ValueError:
            print('请输入数字')


def use_different_except():
    """
    不同的异常类型
    :return:
    """
    try:
        num = int(input("请输入整数："))
        result = 8 / num
        print(result)
    except ValueError:
        print("请输入整数")
    except ZeroDivisionError:
        print("除 0 错误")
    except Exception as result:
        print(result)


def use_else_finally():
    try:
        num = int(input("请输入整数："))
        result = 8 / num
        print(result)
        return None
    except ValueError:
        print("请输入正确的整数")
    except ZeroDivisionError:
        print("除 0 错误")
    except Exception as result:
        print("未知错误 %s" % result)
    else:
        print("正常执行")
    finally:  # 不受return的影响
        print("执行完成，但是不保证正确")


if __name__ == '__main__':
    # use_except()
    # use_different_except()
    use_else_finally()
